import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
import { PresetValue, DurationUnitType, DurationUnitOption } from "./type";

dayjs.extend(duration);

const toISOStringDuration = (value: number, unit: DurationUnitType) =>
  dayjs.duration(value, unit).toISOString();

const PRESET_ITEMS_TRANSLATION = {
  [PresetValue.TODAY]: "今天",
  [PresetValue.YESTERDAY]: "昨天",
  [PresetValue.THIS_WEEK]: "本周",
  [PresetValue.LAST_WEEK]: "上周",
  [PresetValue.THIS_MONTH]: "本月",
  [PresetValue.LAST_MONTH]: "上月",
};

const DEFAULT_PRESET_ITEMS_DATA: PresetValue[] = [
  PresetValue.TODAY,
  PresetValue.YESTERDAY,
  PresetValue.THIS_WEEK,
  PresetValue.LAST_WEEK,
  PresetValue.THIS_MONTH,
  PresetValue.LAST_MONTH,
];

const DEFAULT_RELATIVE_ITEMS_DATA = [
  toISOStringDuration(5, "m"),
  toISOStringDuration(10, "m"),
  toISOStringDuration(15, "m"),
  toISOStringDuration(30, "m"),
  toISOStringDuration(1, "h"),
  toISOStringDuration(2, "h"),
  toISOStringDuration(6, "h"),
  toISOStringDuration(12, "h"),
];

const DURATION_UNIT: DurationUnitType[] = ["m", "h", "d", "M", "y"];

const DEFAULT_DURATION_UNIT_OPTIONS: DurationUnitOption[] = [
  { value: "m", label: "分钟" },
  { value: "h", label: "小时" },
  { value: "d", label: "天" },
  { value: "M", label: "月" },
  { value: "y", label: "年" },
];

export {
  DEFAULT_PRESET_ITEMS_DATA,
  DEFAULT_RELATIVE_ITEMS_DATA,
  PRESET_ITEMS_TRANSLATION,
  DURATION_UNIT,
  DEFAULT_DURATION_UNIT_OPTIONS,
};
